package com.beerandjesus.common.io;

import java.io.File;
import java.util.StringTokenizer;

/**
 * User: reverend
 * Date: Nov 6, 2004
 * Time: 10:55:34 AM
 */
public class TokenizedFile {
    private File file;
    private String extension;
    private String nameRoot;
    private static final String DEFAULT_SEPERATOR = ".";

    public TokenizedFile(File f) {
        this.file = f;
        this.extension = "";
        this.nameRoot = "";
        StringTokenizer tokenizer = new StringTokenizer(file.getName(), DEFAULT_SEPERATOR, false);
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken();
            if (!tokenizer.hasMoreTokens()) {
                extension = token;
            } else {
                nameRoot = (nameRoot.equals("") ? "" : DEFAULT_SEPERATOR) + token;
            }
        }
    }

    public String extension() {
        return extension;
    }

    public String nameRoot() {
        return nameRoot;
    }

    public String extensionWithSeperator() {
        return DEFAULT_SEPERATOR + extension;
    }

    public File asFile() {
        return file;
    }
}
